<?php


namespace app\admin\controller\virtual;

use app\admin\model\PushStoreRule as PushStoreRuleModel;
use think\Request;

class PushStoreRule
{
    public function list(Request $request)
    {
        $title = $request->param("title");
        $key = $request->param("key");
        $staffNo = $request->param("staff_no");
        $res = PushStoreRuleModel::list($title,$key,$staffNo);
        return successJson("success",$res);
    }

    public function add(Request $request)
    {
        $title = $request->param("title");
        $key = $request->param("key");
        $sta = $request->param("standard");
        $val = $request->param("val");
        if(!$val){
            return failedJson("val 不能为空~");
        }
        $u = $request->_user;
        $p = PushStoreRuleModel::add($title,$key,$sta,$val, $u["staff_no"], $u["staff_name"]);
        if($p) return failedJson($p);
        return successJson("success");
    }

    public function up(Request $request)
    {
        $id = $request->param("id");
        $title = $request->param("title");
        $key = $request->param("key");
        $sta = $request->param("standard");
        $val = $request->param("val");
        if(!$val){
            return failedJson("val 不能为空~");
        }
        $u = $request->_user;
        $p = PushStoreRuleModel::up($title,$key,$sta,$val, $u["staff_no"], $id);
        if($p) return failedJson($p);
        return successJson("success");
    }

    public function del(Request $request)
    {
        $id = $request->param("id");
        $p = PushStoreRuleModel::del($id);
        if($p) return failedJson($p);
        return successJson("success");
    }

    public function det(Request $request){
        $id = $request->param("id");
        $p = PushStoreRuleModel::det($id);
        return successJson("success",$p);
    }
}